package com.fr.data.core.db.handler;

import com.fr.base.StringUtils;
import com.fr.data.core.db.dialect.Dialect;
import com.fr.util.Utils;
import java.io.Reader;
import java.io.StringReader;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ClobTypeHandler
  implements SQLTypeHandler
{
  public void setValue(PreparedStatement paramPreparedStatement, int paramInt1, Object paramObject, int paramInt2, Dialect paramDialect)
    throws SQLException
  {
    String str = (String)paramObject;
    if (str != null)
    {
      StringReader localStringReader = new StringReader(str);
      paramPreparedStatement.setCharacterStream(paramInt1, localStringReader, str.length());
    }
    else
    {
      paramPreparedStatement.setNull(paramInt1, 2005);
    }
  }

  public Object getValue(ResultSet paramResultSet, int paramInt1, int paramInt2, Dialect paramDialect)
    throws SQLException
  {
    Object localObject;
    if (paramInt2 == -1)
    {
      localObject = paramResultSet.getCharacterStream(paramInt1);
      return Utils.reader2String((Reader)localObject);
    }
    if (paramInt2 == 1111)
    {
      localObject = paramResultSet.getString(paramInt1);
      if (StringUtils.isBlank((String)localObject))
        return new ClobDelegate(paramResultSet.getClob(paramInt1));
      return localObject;
    }
    return new ClobDelegate(paramResultSet.getClob(paramInt1));
  }
}